<template>
	<view class="visit">
		<view style="width:100%;height: 100rpx;">
			<input class="query-list" confirm-type="搜索" v-model="keyword" placeholder-class="input-placeholder" placeholder="输入员工姓名进行搜索" @input="doSearch()"></input>
		</view>
		<view class="content-list">
			<view class="item" v-for="(user, index) in result" :key="index" @click="showdetails(user)">
				<view class="left">
					<image :src="user.header" ></image>
				</view>
				<view class="center">
					<view class="title1">{{user.name}}</view>
					<view class="title2">部门：{{user.department.name}}</view>
					<view class="title2">职位：{{user.position.name}}</view>
				</view>
				<view class="right">
					<view class="title3">{{user.phone}}</view>
					<view class="title3">{{user.email}}</view>
				</view>
			</view>
		</view>
		<view class="add-round bg-deepBlue" :class="'bg-' + themeColor.name" @click="navToAdd()">
			<text class="cuIcon-add text-xxl"></text>
		</view>
		
	</view>

</template>

<script>
	import phonebook from '@/utils/data.js';
	import {
		worksList
	} from '@/api/userInfo';
	import rfLoadMore from '@/components/oa-load-more/oa-load-more';
	import moment from '@/common/moment';
	import $mAssetsPath from '@/config/assets.config';
	import oaEmpty from '@/components/oa-empty';
	import { config } from '../../config/api.config.js';
	export default {
		components: {
			rfLoadMore,
			oaEmpty
		},
		data() {
			return {
				worksList: [],
				page: 1,
				// cate_id: '',
				loadingType: 'more',
				loading: true,
				hasLogin: false,
				moneySymbol: this.moneySymbol,
				// 控制滑动效果
				theIndex: null,
				oldIndex: null,
				keyword: '', // 搜索框内容
				show: false,
				result: [] // 获取的通讯录信息
			};
		},
		filters: {
			time(val) {
				return moment(val * 1000).format('YYYY-MM-DD HH:mm:ss');
			},
		},
		async onShow(options) {
			await this.initData();
		},

		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.worksList = [];
			this.loading = true;
			this.getworksList('refresh');
		},
		// 加载更多
		onReachBottom() {
			if (this.loadingType === 'nomore') return;
			this.page++;
			this.getworksList();
		},
		
		onShow() {
		  // 这是为了返回时初始化数据
		  // this.result = phonebook.phonebook;
			// this.getresult();
		  this.result = [];
		  this.page = 1;
		  this.doSearch(); // 获取搜索后返回的通讯录信息
		},

		methods: {
			// 新增员工
			navToAdd() {
				if(wx.getStorageSync('tokenStr')){
					wx.navigateTo({
						url: `/pages/works/detail`
					})
				}else {
					wx.navigateTo({
						url: `/pages/public/login`
					});
					this.$mHelper.toast('请先登录。。。');
				}
			},
			// 获取搜索后返回的通讯录信息
			doSearch() {
				var page = 1;
				var size = 100;
				var that = this;
				const headers = {
					authentication: wx.getStorageSync('tokenStr')
				};
				var url = '';
				if (!this.keyword) {
					url = `http://121.36.218.32:9887/clouddocument/admin/emp/${page}/${size}`;
					// url = '${config.host}/emp/';
				} else {
					url = `http://121.36.218.32:9887/clouddocument/admin/emp/?currentPage=${page}&size=${size}&name=${this.keyword}`;
				}
				wx.request({
					url: url,
					method: 'get',
					header: headers,
					success(resp) {
						console.log(resp);
						if (that.keyword) {
							that.result = resp.data.data;
						} else {
							that.result = resp.data.list;
						}
					}
				})
			},
			// 点击跳转个人信息详情页面
			showdetails(user) {
			  wx.navigateTo({
			  	url: `/pages/works/detail?user=${JSON.stringify(user)}`
			  })
			},
			
			// 数据初始化
			initData() {
				this.hasLogin = this.$mStore.getters.hasLogin;
				this.page = 1;
				this.worksList.length = 0;
				this.getworksList();
				uni.setNavigationBarColor({
					frontColor: '#ffffff',
					backgroundColor: this.themeColor.color,
					animation: {
						duration: 400,
						timingFunc: 'easeIn'
					}
				})
			},
			// 获取资料列表
			async getworksList(type) {
				if (!this.hasLogin) {
					this.loading = false;
					if (type === 'refresh') uni.stopPullDownRefresh();
					uni.removeTabBarBadge({
						index: this.$mConstDataConfig.worksIndex
					});
					return;
				}
				await this.$http.get(`${worksList}`, {
						page: this.page
					}).then(r => {
						this.loading = false;
						if (type === 'refresh') {
							uni.stopPullDownRefresh();
						}
						this.loadingType = r.data.length === 10 ? 'more' : 'nomore';
						this.worksList = [...this.worksList, ...r.data];
					})
					.catch(() => {
						this.loading = false;
						if (type === 'refresh') {
							uni.stopPullDownRefresh();
						}
					});
			},
			navToLogin(route) {
				this.$mRouter.push({
					route
				});
			},
			navTo(route) {
				this.$mRouter.push({
					route
				});
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: $page-color-base;
	}

	.visit {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		height: 1050rpx;
		overflow: hidden;
		/** 搜索框样式 */
		.query-list {
			width:90%;
			margin: 15rpx auto;
			border-radius: 10rpx;
			box-shadow: 10rpx 10rpx #EEEEEE;
		}
		/** 通讯录列表 */
		.content-list {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100%;
			height: 80%;
			overflow-y: auto;
			/** 每个通讯录卡片的样式 */
			.item {
				display: flex;
				justify-content: space-between;
				width: 94%;
				height: 140rpx;
				margin-bottom: 30rpx;
				border: 1rpx solid #FFFFFF;
				border-radius: 20rpx;
				background-color: #FFFFFF;
				box-shadow: 10rpx 10rpx #EEEEEE;
				.left {
					width: 20%;
					height: 120rpx;
					image {
						display: inline-block;
						width:100rpx;
						height: 100rpx;
						border-radius: 50rpx;
						margin: 10rpx 15rpx;
					}
				}
				.center {
					width: 40%;
					height: 120rpx;
					display: flex;
					flex-direction: column;
					.title1 {
						font-size: 32rpx;
						font-weight: bolder;
					}
					.title2 {
						font-size: 28rpx;
					}
				}
				.right {
					width: 40%;
					height: 120rpx;
					display: flex;
					flex-direction: column;
					.title3 {
						display: inline-block;
						height: 60rpx;
						line-height: 60rpx;
						font-size: 30rpx;
					}
				}
			}
		}
		.uni-media-list-logo {
			width: 180rpx;
			height: 140rpx;
		}

		.uni-media-list-body {
			height: auto;
			justify-content: space-around;
		}

		.uni-media-list-text-top {
			height: 74rpx;
			font-size: 28rpx;
			overflow: hidden;
		}

		.uni-media-list-text-bottom {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
		}

		.add-round {
			position: fixed;
			z-index: 999;
			right: 30rpx;
			bottom: 30rpx;
			border-radius: 50%;
			width: 120rpx;
			height: 120rpx;
			color: #fff;
			text-align: center;
			line-height: 120rpx;
			font-weight: 100;
			font-size: 80rpx;
		}

		.notify-list {
			margin-top: 20upx;

			.read {
				text-align: right;
				margin-right: $spacing-base;
				margin-top: $spacing-base;
				margin-bottom: $spacing-sm;

				text {
					margin-left: $spacing-base;
				}
			}

			.row {
				width: calc(94%);
				// height: calc(22vw + 40upx);
				height: calc(14vw + 40upx);
				margin: 0 auto $spacing-base;
				border-radius: 15upx;
				box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.1);
				display: flex;
				align-items: center;
				position: relative;
				overflow: hidden;
				z-index: 4;
				border: 0;

				.menu {
					.iconfont {
						color: #fff;
						font-size: 60upx;
					}

					position: absolute;
					width: 29%;
					height: 100%;
					right: 0;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #fff;
					z-index: 2;
				}

				.carrier {
					@keyframes showMenu {
						0% {
							transform: translateX(0);
						}

						100% {
							transform: translateX(-30%);
						}
					}

					@keyframes closeMenu {
						0% {
							transform: translateX(-30%);
						}

						100% {
							transform: translateX(0);
						}
					}

					&.open {
						animation: showMenu 0.25s linear both;
					}

					&.close {
						animation: closeMenu 0.15s linear both;
					}

					background-color: #fff;
					position: absolute;
					width: 100%;
					padding: 0 0;
					height: 100%;
					z-index: 3;
					display: flex;
					align-items: center;
				}
			}

			.notify-wrapper {
				background-color: $color-white;
				width: 100%;
				// padding: $spacing-base $spacing-lg $spacing-base $spacing-lg;
				padding: 10rpx 10rpx;
				// margin: $spacing-base 0 0;
				margin: 0rpx;
				border-radius: 15upx;
				position: relative;
				
				.pro-content {
					display: flex;
					justify-content: space-between;
				}

				.title {
					font-size: $font-lg;
					color: $font-color-dark;
					font-weight: 500;
					margin: 0 0 $spacing-sm;
				}

				.content {
					font-size: $font-sm;
					color: $font-color-base;
					height: 75upx;
					line-height: 36upx;
				}

				.time {
					font-size: $font-base;
					color: $font-color-light;
				}

				.type {
					position: absolute;
					top: 26upx;
					left: -10upx;
					border: none;
					font-size: $font-sm;
					opacity: 0.8;
				}

				.un-read {
					display: inline-block;
					width: 12upx;
					height: 12upx;
					border-radius: 50%;
					position: absolute;
					top: 32upx;
					right: 30upx;
				}
			}
		}

		.notify-empty {
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			height: 100vh;
			padding-bottom: 100upx;
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			background: #fff;

			.iconfont {
				font-size: $font-lg + 100upx;
			}

			.empty-tips {
				display: flex;
				font-size: $font-sm + 2upx;
				color: $font-color-disabled;

				.navigator {
					margin-left: 16upx;
				}
			}
		}

		.works-empty {
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			height: 100vh;
			padding-bottom: 100upx;
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			background: #fff;

			.iconfont {
				font-size: $font-lg + 100upx;
			}

			.empty-tips {
				display: flex;
				font-size: $font-sm + 2upx;
				color: $font-color-disabled;

				.navigator {
					margin-left: 16upx;
				}
			}
		}
	}
</style>
